import React, { useState } from 'react';
import { Button } from 'antd';
import LicenseModal from '@/pages/components/modal/LicenseModal';

import CommonModal from "./CommonModal";
import usePermission from '@/hooks/event/usePermission';


interface LicenseModalProps {
  visible: boolean;
  onCancel: () => void;
}

const LicenseConfirmModal: React.FC<LicenseModalProps> = ({
  visible,
  onCancel,
}) => {

  const [isLicenseModalOpen, setIsLicenseModalOpen] = useState(false);
  const { isAdmin } = usePermission();

  const handleActivateClick = () => {
    onCancel()
    setIsLicenseModalOpen(true);
  };

  const handleLicenseCancel = () => {
    setIsLicenseModalOpen(false);
  };

  return (
    <>
      <CommonModal showCancelBtn={false} showOkBtn={false} open={visible} width={'300px'}>
        <div className='flex flex-col justify-center items-center' style={{ height: '100px' }}>
          <div className='text-center text-base text-[#474C5F]'>
            {`暂未获得授权，无法使用${isAdmin ? '，请输入授权码激活' : '，请通知管理员输入授权码激活'}`}
          </div>
          <div className='flex justify-between mt-6'>
            <Button onClick={onCancel}>
              取消
            </Button>
            <Button
              type="primary"
              className='ml-10'
              onClick={isAdmin ? handleActivateClick : onCancel}>
              确定
            </Button>
          </div>
        </div>
      </CommonModal>
      <LicenseModal
        visible={isLicenseModalOpen}
        onCancel={handleLicenseCancel}
      />
    </>
  );
};

export default LicenseConfirmModal;